package cn.hy.today;

class Solution_2765 {
    public int alternatingSubarray(int[] nums) {
        int ans = -1;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                int length = j - i + 1;
                // 观察交替数组 1，-1， 1 ，数据差的绝对值 都是 1
                if (nums[j] - nums[i] == (length - 1) % 2) {
                    ans = Math.max(ans, length);
                } else {
                    break;
                }
            }
        }
        return ans;
    }
}